package com.technician.model.enums;

import org.apache.commons.lang3.ObjectUtils;

import java.util.Arrays;
import java.util.List;
import java.util.stream.Collectors;

public enum HttpStatusEnum {

    // 默认
    SUCCESS_RESPONSE(200,"成功"),
    ERROR_RESPONSE(400,"系统异常"),

    // 校验异常
    CHECKPASSWORK_NOTEQUALS(400021,"两次输入的密码不一致"),
    PARAMS_ERROR(400022,"请求参数异常"),

    // 用户异常状态
    USER_EXIST(400011,"账号已存在"),
    USER_WITHOUT_LOGIN(400012,"用户未登录"),
    ACCESS_ERROR(400013,"权限不足"),
    USER_NOT_EXIST(400014,"账号不存在"),

    // 系统错误
    DATABASE_ERROR(500001,"数据库异常");






    int code;

    String message;

    HttpStatusEnum(int code, String message) {
        this.code = code;
        this.message = message;
    }
    /**
     * 获取值列表
     *
     * @return
     */
    public static List<String> getValues() {
        return Arrays.stream(values()).map(item -> item.message).collect(Collectors.toList());
    }

    /**
     * 根据 value 获取枚举
     *
     * @param value
     * @return
     */
    public static HttpStatusEnum getEnumByValue(String value) {
        if (ObjectUtils.isEmpty(value)) {
            return null;
        }
        for (HttpStatusEnum anEnum : HttpStatusEnum.values()) {
            if (anEnum.message.equals(value)) {
                return anEnum;
            }
        }
        return null;
    }
    

    public int getCode() {
        return code;
    }

    public String getMessage() {
        return message;
    }
}
